(() => {
  function e(e) {
    0 == $("#syncd-pannel").length &&
      $("body").append(
        '\n<div id="syncd-pannel" style="background:#111;position: fixed;\nuser-select: none;\nbottom: 30px;\nright: 12px;\nleft: initial;\nwidth: 306px;\nheight: 45px;\nborder: 0px;\nz-index: 2147483646;\nclip: auto;\ncolor: white;\nfont-size: 14px;\ndisplay: none;">\n<div>\n  <div style="position: absolute;\n  left: 10px;\n  width: 240px;\n  height: 20px;\n  line-height: 20px;\n  text-align:left;\n  overflow: hidden;\n  cursor: pointer;\n  top: 12px;" id="syncd-title">正在查找文章...</div>\n  <div id="closebtn" style="position: absolute;\n  cursor: pointer;\n  right: 10px;\n  top: 10px;"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="#f4f4f4" xmlns:xlink="http://www.w3.org/1999/xlink">\n  <path d="M5.69999 5L5 5.70004L11.3 12.0001L5 18.3L5.69999 19L12 12.7L18.3 19L19 18.3L12.7 12.0001L19 5.70004L18.3 5.00012L12 11.3L5.69999 5Z"></path>\n</svg></div>\n</div>\n</div>\n',
      ),
      $("#closebtn").click(function () {
        $("#syncd-pannel").remove();
      });
    var t = chrome.runtime.getURL("view.html"),
      n = navigator.userAgent.match(/Chrome\/(\d+)/),
      i = (n && parseInt(n[1], 10)) || 0;
    if ($(".wechatsync-viewer").length)
      (r = $(".wechatsync-viewer")), (o = $(".wechatsync-viewer iframe"));
    else {
      console.log("add viwer");
      var o,
        r,
        a = document.createElement("div"),
        c = a.createShadowRoot
          ? a.createShadowRoot()
          : a.webkitCreateShadowRoot
            ? a.webkitCreateShadowRoot()
            : a,
        l = document.createElement(i >= 37 ? "dialog" : "div");
      (o = $(
        '<iframe src="' + t + '" name="' + window.location.href + '"></iframe>',
      )).css({ width: "100%", height: "100%", border: "none" }),
        $(l)
          .css({
            position: "fixed",
            width: "100%",
            height: "100%",
            top: 0,
            left: 0,
            background: "rgb(251, 251, 251)",
            zIndex: "2147483647",
            display: "block",
            padding: 0,
            border: "none",
            margin: 0,
          })
          .append(o),
        (r = $(l)).css("display", "none"),
        $(c).append($(l)),
        $("body").append(r),
        $(l).addClass("wechatsync-viewer");
    }
    function d() {
      !(function () {
        try {
          var e = new Readability(document.cloneNode(!0)).parse();
          console.log("adoptableArticle", e);
        } catch (e) {
          console.log("Readability.error", e);
        }
        var t = $(ReaderArticleFinderJS.adoptableArticle().outerHTML);
        function n(e) {
          if (!e) return null;
          var t = e.src,
            n = $(e);
          return (
            n.attr("data-src") && (t = n.attr("data-src")),
            t.indexOf("data:image") > -1 && (t = null),
            t
          );
        }
        t.find("a").each(function (e, t) {
          t.setAttribute("href", t.href),
            ("" != t.target && "_self" != t.target.toLowerCase()) ||
              t.setAttribute("target", "_top");
        }),
          t.find("img").each(function (e, t) {
            console.log("img.src", t.src, t), t.setAttribute("src", t.src);
            var n = t.getAttribute("src");
            n
              ? n.indexOf("data:image/svg+xml") > -1 &&
                null != t.getAttribute("data-actualsrc") &&
                t.setAttribute("src", t.getAttribute("data-actualsrc"))
              : (null != t.getAttribute("data-actualsrc") &&
                  t.setAttribute("src", t.getAttribute("data-actualsrc")),
                null != t.getAttribute("_src") &&
                  (console.log("use _src"),
                  t.setAttribute("src", t.getAttribute("_src")))),
              console.log("after", t);
          });
        var i = {
          article: t[0].outerHTML,
          url: window.location.href,
          leadingImage: n(ReaderArticleFinderJS.leadingImage),
          mainImage: n(ReaderArticleFinderJS.mainImageNode()),
          pageNumber: ReaderArticleFinderJS.pageNumber,
          description: ReaderArticleFinderJS.pageDescription(),
          nextPage: ReaderArticleFinderJS.nextPageURL(),
          title: ReaderArticleFinderJS.articleTitle(),
          rtl: !ReaderArticleFinderJS.articleIsLTR(),
        };
        console.log("", o, o[0], ReaderArticleFinderJS.adoptableArticle(), i),
          o[0].contentWindow.postMessage(JSON.stringify(i), "*");
      })(),
        r.css("display", "block"),
        o[0].contentWindow.postMessage(
          JSON.stringify({ method: "openPannel" }),
          "*",
        );
    }
    function s(e, t) {
      var n = 0,
        i = setInterval(function () {
          if (n > 20) return e && e(), clearInterval(i);
          ReaderArticleFinderJS.isReaderModeAvailable() &&
            (clearInterval(i), t && t()),
            n++;
        }, 1e3);
    }
    function g() {
      var e = null;
      try {
        (e = new Readability(document.cloneNode(!0)).parse()),
          console.log("adoptableArticle", e);
      } catch (e) {
        console.log("Readability.error", e);
      }
      return e;
    }
    if (
      ($("#syncd-title").click(function () {
        d();
      }),
      e)
    )
      if (ReaderArticleFinderJS.isReaderModeAvailable())
        s(
          function () {},
          function () {
            d();
          },
        );
      else if (null != g()) {
        setTimeout(function () {
          var e, t, n;
          (e = g()),
            (t = $(e.content)),
            (n = {
              article: e.content,
              url: window.location.href,
              leadingImage: t.find("img").eq(0).attr("src"),
              mainImage: t.find("img").eq(0).attr("src"),
              pageNumber: 1,
              description: e.excerpt,
              nextPage: 0,
              title: document.title,
              rtl: !1,
            }),
            console.log("", o, o[0], n),
            o[0].contentWindow.postMessage(JSON.stringify(n), "*"),
            r.css("display", "block"),
            o[0].contentWindow.postMessage(
              JSON.stringify({ method: "openPannel" }),
              "*",
            );
        }, 1e3);
      } else {
        var u = $("article");
        if (u.length) {
          setTimeout(function () {
            var e;
            (e = {
              article: u[0].outerHTML,
              url: window.location.href,
              leadingImage: u.find("img").attr("src"),
              mainImage: u.find("img").attr("src"),
              pageNumber: 1,
              description: $("meta[name=description]").attr("content"),
              nextPage: 0,
              title: document.title,
              rtl: !1,
            }),
              console.log("", o, o[0], e),
              o[0].contentWindow.postMessage(JSON.stringify(e), "*"),
              r.css("display", "block"),
              o[0].contentWindow.postMessage(
                JSON.stringify({ method: "openPannel" }),
                "*",
              );
          }, 1e3);
        } else alert("无法识别到文章");
      }
    else
      $("#syncd-pannel").show(),
        s(
          function () {
            $("#syncd-title").html("未找到"),
              setTimeout(function () {
                $("#syncd-pannel").remove();
              }, 2e3);
          },
          function () {
            $("#syncd-title").html(ReaderArticleFinderJS.articleTitle());
          },
        );
    window.addEventListener("message", function (e) {
      try {
        "closeMe" == JSON.parse(e.data).method && r.css("display", "none");
      } catch (e) {}
    }),
      chrome.runtime.onMessage.addListener(function (e, t, n) {
        console.log("page.js revice", e),
          o[0].contentWindow.postMessage(JSON.stringify(e), "*");
      });
  }
  console.log("page.js", ReaderArticleFinderJS, "Readability", Readability),
    window.location.href.indexOf("mp.weixin.qq.com/cgi-bin/appmsg") > -1 &&
      window.addEventListener("message", function (e) {
        try {
          "GoTemplateCenter" == JSON.parse(e.data).method &&
            window.open(chrome.runtime.getURL("templates.html"));
        } catch (e) {
          console.log("page listner", e);
        }
      });
  var t = {
    fetchArticle: function (t, n, i) {
      e(!0);
    },
  };
  chrome.extension.onRequest.addListener(function (e, n, i) {
    e.method && t[e.method](e, n, i);
  }),
    console.log("discuz_cache"),
    window.location.href.indexOf("loaddraft") > -1 ||
    (document.referrer && document.referrer.indexOf("loaddraft") > -1)
      ? (function e() {
          if (window.frames["uchome-ifrHtmlEditor"] || window.e_iframe) {
            chrome.extension.sendMessage(
              { action: "getCache", name: "discuz_cache" },
              function (e) {
                var t,
                  n = JSON.parse(e.result.discuz_cache);
                console.log("getCache return", e);
                try {
                  (t = n),
                    console.log("extractPage", t),
                    document.querySelector("#subject")
                      ? (console.log("set title"),
                        (document.querySelector("#subject").value = t.title))
                      : console.log("no title"),
                    window.e_iframe
                      ? (window.e_iframe.contentWindow.document.body.innerHTML =
                          t.content)
                      : console.log("not frame"),
                    window.frames["uchome-ifrHtmlEditor"] &&
                      ((document.querySelector("#title").value = t.title),
                      (window.frames[
                        "uchome-ifrHtmlEditor"
                      ].window.frames.HtmlEditor.document.body.innerHTML =
                        t.content));
                } catch (e) {
                  console.log("extractPage.error", e);
                }
              },
            );
          } else console.log("not found;"), setTimeout(e, 500);
        })()
      : console.log("skip");
})();
(() => {
    function e(e) {
      0 == $("#syncd-pannel").length &&
        $("body").append(
          '\n<div id="syncd-pannel" style="background:#111;position: fixed;\nuser-select: none;\nbottom: 30px;\nright: 12px;\nleft: initial;\nwidth: 306px;\nheight: 45px;\nborder: 0px;\nz-index: 2147483646;\nclip: auto;\ncolor: white;\nfont-size: 14px;\ndisplay: none;">\n<div>\n  <div style="position: absolute;\n  left: 10px;\n  width: 240px;\n  height: 20px;\n  line-height: 20px;\n  text-align:left;\n  overflow: hidden;\n  cursor: pointer;\n  top: 12px;" id="syncd-title">正在查找文章...</div>\n  <div id="closebtn" style="position: absolute;\n  cursor: pointer;\n  right: 10px;\n  top: 10px;"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="#f4f4f4" xmlns:xlink="http://www.w3.org/1999/xlink">\n  <path d="M5.69999 5L5 5.70004L11.3 12.0001L5 18.3L5.69999 19L12 12.7L18.3 19L19 18.3L12.7 12.0001L19 5.70004L18.3 5.00012L12 11.3L5.69999 5Z"></path>\n</svg></div>\n</div>\n</div>\n',
        ),
        $("#closebtn").click(function () {
          $("#syncd-pannel").remove();
        });
      var t = chrome.runtime.getURL("view.html"),
        n = navigator.userAgent.match(/Chrome\/(\d+)/),
        i = (n && parseInt(n[1], 10)) || 0;
      if ($(".wechatsync-viewer").length)
        (r = $(".wechatsync-viewer")), (o = $(".wechatsync-viewer iframe"));
      else {
        console.log("add viwer");
        var o,
          r,
          a = document.createElement("div"),
          c = a.createShadowRoot
            ? a.createShadowRoot()
            : a.webkitCreateShadowRoot
              ? a.webkitCreateShadowRoot()
              : a,
          l = document.createElement(i >= 37 ? "dialog" : "div");
        (o = $(
          '<iframe src="' + t + '" name="' + window.location.href + '"></iframe>',
        )).css({ width: "100%", height: "100%", border: "none" }),
          $(l)
            .css({
              position: "fixed",
              width: "100%",
              height: "100%",
              top: 0,
              left: 0,
              background: "rgb(251, 251, 251)",
              zIndex: "2147483647",
              display: "block",
              padding: 0,
              border: "none",
              margin: 0,
            })
            .append(o),
          (r = $(l)).css("display", "none"),
          $(c).append($(l)),
          $("body").append(r),
          $(l).addClass("wechatsync-viewer");
      }
      function d() {
        !(function () {
          try {
            var e = new Readability(document.cloneNode(!0)).parse();
            console.log("adoptableArticle", e);
          } catch (e) {
            console.log("Readability.error", e);
          }
          var t = $(ReaderArticleFinderJS.adoptableArticle().outerHTML);
          function n(e) {
            if (!e) return null;
            var t = e.src,
              n = $(e);
            return (
              n.attr("data-src") && (t = n.attr("data-src")),
              t.indexOf("data:image") > -1 && (t = null),
              t
            );
          }
          t.find("a").each(function (e, t) {
            t.setAttribute("href", t.href),
              ("" != t.target && "_self" != t.target.toLowerCase()) ||
                t.setAttribute("target", "_top");
          }),
            t.find("img").each(function (e, t) {
              console.log("img.src", t.src, t), t.setAttribute("src", t.src);
              var n = t.getAttribute("src");
              n
                ? n.indexOf("data:image/svg+xml") > -1 &&
                  null != t.getAttribute("data-actualsrc") &&
                  t.setAttribute("src", t.getAttribute("data-actualsrc"))
                : (null != t.getAttribute("data-actualsrc") &&
                    t.setAttribute("src", t.getAttribute("data-actualsrc")),
                  null != t.getAttribute("_src") &&
                    (console.log("use _src"),
                    t.setAttribute("src", t.getAttribute("_src")))),
                console.log("after", t);
            });
          var i = {
            article: t[0].outerHTML,
            url: window.location.href,
            leadingImage: n(ReaderArticleFinderJS.leadingImage),
            mainImage: n(ReaderArticleFinderJS.mainImageNode()),
            pageNumber: ReaderArticleFinderJS.pageNumber,
            description: ReaderArticleFinderJS.pageDescription(),
            nextPage: ReaderArticleFinderJS.nextPageURL(),
            title: ReaderArticleFinderJS.articleTitle(),
            rtl: !ReaderArticleFinderJS.articleIsLTR(),
          };
          console.log("", o, o[0], ReaderArticleFinderJS.adoptableArticle(), i),
            o[0].contentWindow.postMessage(JSON.stringify(i), "*");
        })(),
          r.css("display", "block"),
          o[0].contentWindow.postMessage(
            JSON.stringify({ method: "openPannel" }),
            "*",
          );
      }
      function s(e, t) {
        var n = 0,
          i = setInterval(function () {
            if (n > 20) return e && e(), clearInterval(i);
            ReaderArticleFinderJS.isReaderModeAvailable() &&
              (clearInterval(i), t && t()),
              n++;
          }, 1e3);
      }
      function g() {
        var e = null;
        try {
          (e = new Readability(document.cloneNode(!0)).parse()),
            console.log("adoptableArticle", e);
        } catch (e) {
          console.log("Readability.error", e);
        }
        return e;
      }
      if (
        ($("#syncd-title").click(function () {
          d();
        }),
        e)
      )
        if (ReaderArticleFinderJS.isReaderModeAvailable())
          s(
            function () {},
            function () {
              d();
            },
          );
        else if (null != g()) {
          setTimeout(function () {
            var e, t, n;
            (e = g()),
              (t = $(e.content)),
              (n = {
                article: e.content,
                url: window.location.href,
                leadingImage: t.find("img").eq(0).attr("src"),
                mainImage: t.find("img").eq(0).attr("src"),
                pageNumber: 1,
                description: e.excerpt,
                nextPage: 0,
                title: document.title,
                rtl: !1,
              }),
              console.log("", o, o[0], n),
              o[0].contentWindow.postMessage(JSON.stringify(n), "*"),
              r.css("display", "block"),
              o[0].contentWindow.postMessage(
                JSON.stringify({ method: "openPannel" }),
                "*",
              );
          }, 1e3);
        } else {
          var u = $("article");
          if (u.length) {
            setTimeout(function () {
              var e;
              (e = {
                article: u[0].outerHTML,
                url: window.location.href,
                leadingImage: u.find("img").attr("src"),
                mainImage: u.find("img").attr("src"),
                pageNumber: 1,
                description: $("meta[name=description]").attr("content"),
                nextPage: 0,
                title: document.title,
                rtl: !1,
              }),
                console.log("", o, o[0], e),
                o[0].contentWindow.postMessage(JSON.stringify(e), "*"),
                r.css("display", "block"),
                o[0].contentWindow.postMessage(
                  JSON.stringify({ method: "openPannel" }),
                  "*",
                );
            }, 1e3);
          } else alert("无法识别到文章");
        }
      else
        $("#syncd-pannel").show(),
          s(
            function () {
              $("#syncd-title").html("未找到"),
                setTimeout(function () {
                  $("#syncd-pannel").remove();
                }, 2e3);
            },
            function () {
              $("#syncd-title").html(ReaderArticleFinderJS.articleTitle());
            },
          );
      window.addEventListener("message", function (e) {
        try {
          "closeMe" == JSON.parse(e.data).method && r.css("display", "none");
        } catch (e) {}
      }),
        chrome.runtime.onMessage.addListener(function (e, t, n) {
          console.log("page.js revice", e),
            o[0].contentWindow.postMessage(JSON.stringify(e), "*");
        });
    }
    console.log("page.js", ReaderArticleFinderJS, "Readability", Readability),
      window.location.href.indexOf("mp.weixin.qq.com/cgi-bin/appmsg") > -1 &&
        window.addEventListener("message", function (e) {
          try {
            "GoTemplateCenter" == JSON.parse(e.data).method &&
              window.open(chrome.runtime.getURL("templates.html"));
          } catch (e) {
            console.log("page listner", e);
          }
        });
    var t = {
      fetchArticle: function (t, n, i) {
        e(!0);
      },
    };
    chrome.extension.onRequest.addListener(function (e, n, i) {
      e.method && t[e.method](e, n, i);
    }),
      console.log("discuz_cache"),
      window.location.href.indexOf("loaddraft") > -1 ||
      (document.referrer && document.referrer.indexOf("loaddraft") > -1)
        ? (function e() {
            if (window.frames["uchome-ifrHtmlEditor"] || window.e_iframe) {
              chrome.extension.sendMessage(
                { action: "getCache", name: "discuz_cache" },
                function (e) {
                  var t,
                    n = JSON.parse(e.result.discuz_cache);
                  console.log("getCache return", e);
                  try {
                    (t = n),
                      console.log("extractPage", t),
                      document.querySelector("#subject")
                        ? (console.log("set title"),
                          (document.querySelector("#subject").value = t.title))
                        : console.log("no title"),
                      window.e_iframe
                        ? (window.e_iframe.contentWindow.document.body.innerHTML =
                            t.content)
                        : console.log("not frame"),
                      window.frames["uchome-ifrHtmlEditor"] &&
                        ((document.querySelector("#title").value = t.title),
                        (window.frames[
                          "uchome-ifrHtmlEditor"
                        ].window.frames.HtmlEditor.document.body.innerHTML =
                          t.content));
                  } catch (e) {
                    console.log("extractPage.error", e);
                  }
                },
              );
            } else console.log("not found;"), setTimeout(e, 500);
          })()
        : console.log("skip");
  })();
  